def convert(s, numRows):
    if numRows < 2:
        return s
    res = ['' for _ in range(numRows)]
    i = 0
    flag = -1
    for c in s:
        res[i] += c
        if i == 0 or i == numRows - 1:
            flag = - flag
        i += flag
    return ''.join(res)

def main():
    s = str(input())
    num = int(input())
    res = convert(s, num)
    print(res)
main()
# 若行数为1时，可直接输出，初始化为numRows个空字符串，用于存放从左往右逐行读取的字符
#i为字符的下标，从0开始，flag用于转向方向，当遇到Z字的转折处时，翻转方向